﻿using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

#nullable disable

namespace LDC_Shop_A.Models.Database
{
    public partial class LDC_ShopAContext : DbContext
    {
        public LDC_ShopAContext()
        {
        }

        public LDC_ShopAContext(DbContextOptions<LDC_ShopAContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Car> Cars { get; set; }
        public virtual DbSet<Good> Goods { get; set; }
        public virtual DbSet<GoodCategory> GoodCategories { get; set; }
        public virtual DbSet<Order> Orders { get; set; }
        public virtual DbSet<OrderItem> OrderItems { get; set; }
        public virtual DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
                optionsBuilder.UseSqlServer("Data Source=119.29.63.234;Initial Catalog=LDC_ShopA;User ID=sa;Password=aa520.0.");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Chinese_PRC_CI_AS");

            modelBuilder.Entity<Car>(entity =>
            {
                entity.ToTable("Car");

                entity.Property(e => e.CraeteTime).HasColumnType("datetime");
            });

            modelBuilder.Entity<Good>(entity =>
            {
                entity.ToTable("Good");

                entity.Property(e => e.CreateTime).HasColumnType("datetime");

                entity.Property(e => e.Desc).IsRequired();

                entity.Property(e => e.Photo)
                    .IsRequired()
                    .HasMaxLength(500);

                entity.Property(e => e.Price).HasColumnType("decimal(18, 2)");

                entity.Property(e => e.Title)
                    .IsRequired()
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<GoodCategory>(entity =>
            {
                entity.HasKey(e => e.CateId);

                entity.ToTable("GoodCategory");

                entity.Property(e => e.CateName)
                    .IsRequired()
                    .HasMaxLength(20);
            });

            modelBuilder.Entity<Order>(entity =>
            {
                entity.ToTable("Order");

                entity.Property(e => e.OrderId).HasComment("订单Id");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasComment("下单时间");

                entity.Property(e => e.OrderNum)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasComment("订单编号");

                entity.Property(e => e.OrderPrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasComment("订单总额");

                entity.Property(e => e.OrderState).HasComment("订单状态（0-待付款、1-待发货（已付款）、2-待收货）");

                entity.Property(e => e.OrderTotal).HasComment("订单商品数量");

                entity.Property(e => e.PayTime)
                    .HasColumnType("datetime")
                    .HasComment("支付时间");

                entity.Property(e => e.SendTime)
                    .HasColumnType("datetime")
                    .HasComment("发货时间");

                entity.Property(e => e.ShipCom)
                    .HasMaxLength(50)
                    .HasComment("快递公司");

                entity.Property(e => e.ShipNum)
                    .HasMaxLength(50)
                    .HasComment("快递单号");

                entity.Property(e => e.UserId).HasComment("用户Id");
            });

            modelBuilder.Entity<OrderItem>(entity =>
            {
                entity.ToTable("OrderItem");

                entity.Property(e => e.OrderItemId).HasComment("订单明细Id");

                entity.Property(e => e.GoodCount).HasComment("购买数量");

                entity.Property(e => e.GoodCover)
                    .IsRequired()
                    .HasMaxLength(255)
                    .HasComment("商品图片");

                entity.Property(e => e.GoodId).HasComment("商品Id");

                entity.Property(e => e.GoodName)
                    .IsRequired()
                    .HasMaxLength(255)
                    .HasComment("商品名称");

                entity.Property(e => e.GoodPrice)
                    .HasColumnType("decimal(18, 2)")
                    .HasComment("商品价格");

                entity.Property(e => e.OrderId).HasComment("订单ID");
            });

            modelBuilder.Entity<User>(entity =>
            {
                entity.ToTable("User");

                entity.Property(e => e.UserId).HasComment("用户Id");

                entity.Property(e => e.CreateTime)
                    .HasColumnType("datetime")
                    .HasComment("注册时间");

                entity.Property(e => e.Mobile)
                    .IsRequired()
                    .HasMaxLength(11)
                    .IsUnicode(false)
                    .HasComment("手机号");

                entity.Property(e => e.Nickname)
                    .HasMaxLength(20)
                    .HasComment("昵称");

                entity.Property(e => e.Password)
                    .IsRequired()
                    .HasMaxLength(50)
                    .IsUnicode(false)
                    .HasComment("密码");

                entity.Property(e => e.Photo)
                    .HasMaxLength(300)
                    .HasComment("头像");

                entity.Property(e => e.Salt)
                    .HasMaxLength(4)
                    .IsUnicode(false)
                    .IsFixedLength(true);
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
